<template>
  <div class="login-container">
    <div class="login-box">
      <div class="sculpture">
        <img src="../assets/img/123.jpg" alt="用户头像">
      </div>
      <el-form ref="userForm" :model="userForm" label-width="10%" class="form-box" :rules="userRules"
               style="width: 90%;">
        <el-form-item prop="username" class="el-icon-user" prefix-icon="el-icon-user">
          <el-input v-model="userForm.username" placeholder="请输入用户名" prefix-icon="el-icon-user"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" v-model="userForm.password" show-password placeholder="请输入密码"
                    prefix-icon="el-icon-suitcase"></el-input>
        </el-form-item>
        <el-form-item style="height: 40px">
          <el-button type="primary" class="el-button" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import bScroll from '@/components/scroll/bScroll'

export default {
  name: 'Login',
  data () {
    return {
      userForm: {
        username: 'admin',
        password: 'admin'
      },
      userRules: {
        username: [
          {required: true, message: '请输入用户名', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {min: 5, max: 15, message: '请输入5-15位密码', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    login () {
      this.$refs.userForm.validate((valid) => {
        if (valid) {
          this.$get('/api/hello').then(res => {
            console.log(res)
          }).catch(err => {
            console.log(err)
          })
        } else {
          this.$message({
            showClose: true,
            message: '请正确输入用户名和密码'
          })
        }
      })
    }
  },
  components: {
    bScroll
  }
}
</script>

<style scoped lang="scss">
.view {
  height: 100vh;
}

.login-container {
  background: #2b4b6b;
  position: relative;
  z-index: 20;
  height: 100vh;

  .login-box {
    border-radius: 10px;
    background: #fff;
    width: 450px;
    height: 300px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);

    // 头像
    .sculpture {
      position: relative;
      left: 50%;
      top: 0;
      transform: translate(-50%, -50%);
      height: 130px;
      width: 130px;

      img {
        width: 100%;
        height: 100%;
        border: 3px solid #bfa;
        border-radius: 50%;
      }
    }

    // form-box
    .form-box {
      margin-top: -30px;

      // 调整用户名和密码之间的距离
      .el-form-item {
        display: flex;
        flex: 1;
        width: 100%;

        .el-input {
          display: flex;
        }

        .el-button {
          position: relative;
          left: 50%;
          transform: translateX(-50%);
          width: 240px;
          font-size: 20px;
        }

      }
    }
  }
}


::v-deep .el-form-item__content {
  display: flex;
  flex: 1;
}

i {
  &[class='el-icon-user'] {
    transform: scale(150%);
  }
}


</style>